<template>
    <view :style="objColor">
        <view class="set">
			<view class="set-list v_switch">
			    <view class="u_text">
                    电池电量自动停充保护开关
                    <image src="https://oos-cn.ctyunapi.cn/front-end/static/mobileImg/iconwenhao.png" @click="wenhaoFn()"></image>
                </view>
			    <view class="u_icon">
			        <u-switch v-model="checkedOpen" @change="changeSwitch" size="44"></u-switch>
			    </view>
			</view>

            <view class="set-list v_auto">
			    <view>自动停充电池电量上限(%)</view>
			    <view class="u_auto">
			        <u-number-box v-model="valueSoc" @change="valChange" color="3ebecee" input-width="44" input-height="48"></u-number-box>
			    </view>
			</view>
        </view>

        <!-- 退出登录 -->
        <view class="out" @tap="saveForm()">保存</view>



        <u-modal title="安全防护提示" :show="socInfoShow" confirm-text="我知道了" @confirm="closePopup">
            <view class="p_text">您的爱车在充电过程中，可能会出现因电池过充而导致电池损坏，存在充电事故隐患。为保障您的充电安全，可根据爱车所需电量设置停充SOC，充电达到停充SOC后即可停止充电。</view>
        </u-modal>


    </view>
</template>
<script>
    var app = getApp();
    import { selectMemberSocSetting, saveMemberSocSetting, } from '@/api/mobileUpdate';
    export default {
        data() {
            return {
                socSettingId: null,
                checkedOpen: false,
                valueSoc: 95,

                socInfoShow: false,
            };
        }
        /**
         * 生命周期函数--监听页面加载
         */
        ,
        onLoad: function(options) {

 
        },
        /**
         * 生命周期函数--监听页面显示
         */
        onShow: function() {
            this.getSelectMemberSocSetting()
        },
        onUnload(){
    
        },
        methods: {
            // switch打开或者关闭时触发，值为true或者false
			// 即使不监听此事件，checked此时也会相应的变成true或者false
			changeSwitch(status) {
				console.log(status)
                this.checkedOpen = status
			},
            valChange(e) {
				console.log('当前值为: ' + e.value)
                this.valueSoc = e.value
			},
            //提示弹窗
            wenhaoFn(){
                console.log('问号', this.socInfoShow)
                this.socInfoShow = true
            },
            closePopup(){
				this.socInfoShow = false
			},

            //获取soc设置
			getSelectMemberSocSetting(){
				selectMemberSocSetting(app.globalData.sellerId, uni.getStorageSync('memberId')).then(res=>{
                    console.log(res,'soc.....')
                    if(res.code == 0 && res.data){
                        this.socSettingId = res.data.id
                        this.valueSoc = res.data.soc
                        this.checkedOpen = res.data.safeSwitch
                    }
                })
			},
            // 保存设置
            saveForm() {
                this.saveMemberSocSettingFn()
			},

            //soc设置
			saveMemberSocSettingFn(){
                let datas = {
                    sellerId: app.globalData.sellerId,
                    memberId: uni.getStorageSync('memberId'),
                    soc: this.valueSoc,
                    safeSwitch: this.checkedOpen,
                    id: this.socSettingId,
                }
				saveMemberSocSetting({...datas}).then(res=>{
                    console.log(res,'soc.....')
                    if(res.code == 0){

                        this.getSelectMemberSocSetting()
                    }
                })
			},

        }
    };
</script>
<style lang="less" scoped>
    @import url('./safetyProtection.less');
    @import url('@/commin/flex.less');
    
</style>